/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-09-05 09:49:39
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-10-10 17:37:06
 * @FilePath: /react18-vite-admin/src/api/role.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { service } from '@/service/app/useRequest';
import { RoleListItem, RoleDetial } from '@/typings/api/role';

export const readAllRoles = () => {
    return service<HttpResult<RoleListItem[]>>({
        url: `/admin/api/role/list`,
        method: 'get'
    }).then((res) => {
        return res.data;
    });
};

export class RoleListParam implements PageParam<keyof RoleListItem> {
    current = 1;
    size = 10;
    name?: string;
}

export const readRoleList = (data: RoleListParam) => {
    return service<HttpResult<PageResult<RoleListItem>>>({
        url: '/admin/api/role/search',
        method: 'post',
        data
    }).then((res) => {
        return res.data;
    });
};

export const readRoleDetail = (id: number) => {
    return service<HttpResult<RoleDetial>>({
        url: `/admin/api/role/get/${id}`,
        method: 'get'
    }).then((res) => {
        return res.data;
    });
};

export class RoleParam {
    id?: number;
    name = '';
    description = '';
    menuIdList = [] as number[];
}

export const createOrUpdateRole = (data: RoleParam) => {
    return service<HttpResult>({
        url: '/admin/api/role/save',
        method: 'post',
        data
    }).then((res) => {
        return res.data;
    });
};

export const deleteRole = (id: number) => {
    return service<HttpResult>({
        url: `/admin/api/role/delete/${id}`,
        method: 'post'
    }).then((res) => {
        return res.data;
    });
};
